﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Project_Point_Operate:SqlInteractionBase
    {
        private DataEntity.T_Project_Point _objMessage = null;


        public override bool Insert(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_Point_Insert]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = (DataEntity.T_Project_Point)obj;
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Point_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_Point_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_MainID));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Point_FirstA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_FirstA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_Point_SecondA1", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_SecondA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Point_SecondA2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_SecondA2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Point_ThirdA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_ThirdA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_Point_ThirdA2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_Point_ThirdA2));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_Point::Insert::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }
 
    }
}
